package org.lsms.servlet;

/**
 * modify info servlet 
 * @author ZhanXueliang
 * 2010.8.10
 */


import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.lsms.bean.User;
import org.lsms.dao.impl.DaoImpl;

public class modify_info extends HttpServlet {

	
	public void destroy() {
		super.destroy(); 
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		this.doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		User user = new User();
		//user.setLoginname(request.getParameter("loginname"));
		user.setAddress(request.getParameter("address"));
		user.setAffiliation(request.getParameter("affiliation"));
		user.setCountry(request.getParameter("country"));
		user.setEmail(request.getParameter("email"));
		user.setFax(request.getParameter("fax"));
		user.setFirstname(request.getParameter("firstname"));
		user.setMiddlename(request.getParameter("middlename"));
		user.setLastname(request.getParameter("lastname"));
		user.setPassword(request.getParameter("newpsw"));
		user.setTel(request.getParameter("tel"));
		user.setTitle(request.getParameter("title"));
		
		HttpSession session = request.getSession();
		int userid = Integer.parseInt(session.getAttribute("userid").toString());
		int permission = Integer.parseInt(session.getAttribute("permission").toString());
		DaoImpl impl = new DaoImpl();
		
		if(impl.update_user_info(user,userid)){
			String info = "Information update successfully!";
			switch(permission){
			case 0:
				response.sendRedirect("chair/chair_show_info.jsp?chair_info="+info);
				break;
			case 1:
				response.sendRedirect("member/member_show_info.jsp?member_info="+info);
				break;
			case 2:
				response.sendRedirect("reviewer/reviewer_show_info.jsp?reviewer_info="+info);
				break;
			case 3:
				response.sendRedirect("author/author_show_info.jsp?author_info="+info);
				break;
			case 4:
				response.sendRedirect("admin/admin_show_info.jsp?admin_info="+info);
			}
		}else{
			response.sendRedirect("error/modify_info_failed.jsp");
		}
	}

	public void init() throws ServletException {

	}

}
